// serial_interface.h
#ifndef SERIAL_INTERFACE_H
#define SERIAL_INTERFACE_H

#include <string>
#include <vector>
#include <mutex>
#include <cstdint>
#include <termios.h>

class SerialInterface {
public:
    SerialInterface();
    virtual ~SerialInterface();

    bool open(const std::string& port, int baud_rate);
    void close();
    bool is_open() const;
    bool is_healthy() const;

    ssize_t write(const uint8_t* data, size_t length);
    ssize_t read(uint8_t* buffer, size_t max_length);
    void flush_buffers();

private:
    bool set_serial_attributes(int baud_rate);
    int get_baud_code(int baud_rate) const;

    int fd_ = -1;
    mutable std::mutex mutex_;
};

#endif // SERIAL_INTERFACE_H
